﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
namespace AlbonWeb.Manager.StyleManager
{
    public partial class ModelManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                //绑定item
                string cmdstr = "select * from Style where parentID=0 and active=1";
                SqlHelper.BindDropDownList(ddlItem, "styleName", "ID", SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null);
                ddlItem.Items.Insert(0, "--select style--");

                //绑定Model
                ViewState["limit"] = "where 1=1";
                bindModel();
            }
        }
        protected void bindModel()
        {
            if (modelName.Text.Trim() != "")
            {
                ViewState["limit"] += " and modelName like '%"+modelName.Text.Trim()+"%'";
            }
            if (ddlItem.SelectedIndex != 0)
            {
                ViewState["limit"] += " and styleID=" + ddlItem.SelectedValue;
            }
            string cmdstr = "select count(*) from ModelInfoView " + ViewState["limit"].ToString();
            AspNetPager1.RecordCount = int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).ToString());
            SqlParameter[] parameters = new SqlParameter[]{
                new SqlParameter("@tablename","ModelInfoView"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit",ViewState["limit"].ToString()),
                new SqlParameter("@orderby","createDate desc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "netpager", parameters);
        }
        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            ViewState["limit"] = "where 1=1";
            bindModel();
        }
        //换页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindModel();
        }

        
    }
}